﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace VirtualOperator
{
    public class NetworkConfig
    {
        private string networkName;
        private string virtualNetworkName;
        public string NetworkName { get{return networkName;} set{networkName = value;} }
        public string VirtualNetworkName { get { return virtualNetworkName; } set { virtualNetworkName = value;  } }


        private int delay;
        private int usage;
        private int errorRate;
        public int DelayWeight { get { return delay; } set { delay = value; } }
        public int UsageWeight { get { return usage; } set { usage = value; } }
        public int ErrorRateWeight { get { return errorRate; } set { errorRate = value; } }



        private List<LinkConfig> virtualLinkList = new List<LinkConfig>();
        public List<LinkConfig> VirtualLinkList { get { return virtualLinkList; } set { virtualLinkList = value; } }


        public void Save(string filename)
        {
            // create a writer and open the file
            TextWriter tw = new StreamWriter("Save\\"+filename);
            tw.Write(TransportLayer.NodeToolsLibrary.Serial.SerializeObject(this));

            // close the stream
            tw.Close();
        }
        //wczytanie konfiguracji
        public static NetworkConfig Open(string filename)
        {
            TextReader tr = new StreamReader(filename);
            String str = "";
            String input = null;

            while ((input = tr.ReadLine()) != null)
            {
                str += input;
            }
            tr.Close();
            return ((NetworkConfig)TransportLayer.NodeToolsLibrary.Serial.DeserializeObject(str, typeof(NetworkConfig)));
        }

    }


    public class LinkConfig
    {
        private int sourceManagerID;
        private int targetManagerID;
        private int matrixDelay;
        private int linkDelay;
        private float linkErrorRate;
        private int capacity;

        public int SourceManagerID { get { return sourceManagerID; } set { sourceManagerID = value; } }
        public int TargetManagerID { get { return targetManagerID; } set { targetManagerID = value; } }
        public int MatrixDelay { get { return matrixDelay; } set { matrixDelay = value; } }
        public int LinkDelay { get { return linkDelay; } set { linkDelay = value; } }
        public int Capacity { get { return capacity; } set { capacity = value; } }
        public float LinkErrorRate { get { return linkErrorRate; } set { linkErrorRate = value; } }

        public LinkConfig() { }

        public LinkConfig(int SourceManagerID, int TargetManagerID, int MatrixDelay, int LinkDelay, float LinkErrorRate, int capacity)
        {
            this.sourceManagerID = SourceManagerID;
            this.targetManagerID = TargetManagerID;
            this.matrixDelay = MatrixDelay;
            this.linkDelay = LinkDelay;
            this.linkErrorRate = LinkErrorRate;
            this.capacity = capacity;

        }
    }

    class WrongNetworkTopology : Exception
    {
        public string message {get; private set;}

        public WrongNetworkTopology() { }
        public WrongNetworkTopology(string message) { this.message = message; }
    }
    class VNONotConnected : Exception
    {
        public string message { get; private set; }

        public VNONotConnected() { }
        public VNONotConnected(string message) { this.message = message; }
    }

    class VirtualNetworkExist : Exception
    {
        public string message { get; private set; }

        public VirtualNetworkExist() { }
        public VirtualNetworkExist(string message) { this.message = message; }
    }
}
